package com.example.mobile20306061550420classwork;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class PartRViewAdapter extends RecyclerView.Adapter<PartRViewAdapter.ViewHolder>{
    private  int[] partIds;
    private String[] partNames;

    public PartRViewAdapter(int[] partIds,String[] partNames){
        this.partIds = partIds;
        this.partNames = partNames;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_part,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        return  new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.ivPart.setImageResource(partIds[position]);
        holder.tvPart.setText(partNames[position]);
    }

    @Override
    public int getItemCount() {
        return partIds.length;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView ivPart;
        TextView tvPart;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.ivPart = itemView.findViewById(R.id.ivItemPart);
            this.tvPart = itemView.findViewById(R.id.ivItemPart);
        }
    }
}
